var datas = [];
loadData();

      function showData(arr){
      list_div.innerHTML = "";
         if(arr.length==0){
           list_div.innerHTML = "暂无数据";
           return;
         }
      var allhtml = "";
      allhtml += "<table cellpadding='0' cellspacing='0'" +
         " width='100%'><tr class='theader'>" +
         "<th>超期类型</th><th>超期规则</th><th>创建时间</th>" +
         "<th>修改时间</th><th>操作</th></tr>";
      for(var i=arr.length-1;i>=0;i--){
       var a = arr[i];
       allhtml +=
              "<tr class='list'>" +
              "<td class='ntitle'>"+a.type+"</td>" +
              "<td class='ntitle'>"+a.rule+"</td>" +
              "<td class='ntitle'>"+a.create_time+"</td>" +
              "<td class='ntitle'>"+a.update_time+"</td>" +
              "<td class='ntitle'><a class='edit_a' href='#'>编辑</a>" +
               "<a class='del_a' onclick='del("+a.id+")' href='javascript:;'>删除</a></td>" +
               "</tr>";
       }
          allhtml += "</table>";
          list_div.innerHTML = allhtml;


     }
           function search(){
                loadData({type:stitle.value,rule:stitle.value});
           }
           function loadData(data){
  /*loading.style.display="block";
  ajax("find_all_overtime",data,function(overtimes){
  showData(overtimes);
  loading.style.display="none";
  });*/
             list_div.innerHTML = "";
             loading.style.display = "block";
             ajax("/find_all_overtime",data,function(overtimes){
           
             showData(overtimes);
             loading.style.display = "none";
           });
      }

           function save(){
              if(!type.value){
              type_error.innerHTML = "请您填写超期类型";
           return;
               }

           ajax("/add_overtime",{
               type:type.value,
               rule:rule.value,
               create_time:create_time.value,
               update_time:update_time.value,
               },function(data){
                     alert("新增成功！");
               loadData();
               add_div.style.display = "none";
               list_div.style.display = "block";
               save_btn.style.display = "none";
               add_btn.style.display = "block";
               return_btn.style.display = "none";
               search_div.style.display = "block";
           })

        }
               function del(id){
             if(!confirm("您确定要删除这个数据吗？")){
                return;
        }
             ajax("/del_overtime",{id:id},function(data){
             alert("删除成功！");
              loadData();
         });
        }
           function add(){
                 add_div.style.display = "block";
                 list_div.style.display = "none";
                 save_btn.style.display = "block";
                 add_btn.style.display = "none";
                 search_div.style.display = "none";
                 return_btn.style.display = "block";
           }
           function returnMain(){
                 add_div.style.display = "none";
                 list_div.style.display = "block";
                 save_btn.style.display = "none";
                 add_btn.style.display = "block";
                 search_div.style.display = "block";
                 return_btn.style.display = "none";
}